package com.weichen.studentgameexchange.comment.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.weichen.studentgameexchange.comment.entity.CommentReply;
import com.weichen.studentgameexchange.comment.entity.vo.AddReplyCommentVo;
import com.weichen.studentgameexchange.comment.entity.vo.AddReplyVo;
import com.weichen.studentgameexchange.comment.service.ICommentReplyService;
import com.weichen.studentgameexchange.common.common.Result;
import com.weichen.studentgameexchange.common.exception.ServiceException;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 惟尘
 * @since 2025-02-05
 */
@RestController
@RequestMapping("/comment/commentReply")
public class CommentReplyController {

    @Autowired
    ICommentReplyService commentReplyService;

    /**
     * 新增用户回复评论
     * @param addReplyVo
     * @return
     */
    @Operation(summary = "新增用户回复评论")
    @PostMapping("/user/reply/comment")
    public Result userReplyComment(@RequestBody AddReplyCommentVo addReplyVo){
        return commentReplyService.userReplyComment(addReplyVo);
    }

    /**
     * 新增用户回复回复
     * @param addReplyVo
     * @return
     */
    @Operation(summary = "新增用户回复回复")
    @PostMapping("/user/reply")
    public Result userReply(@RequestBody AddReplyVo addReplyVo){
        return commentReplyService.userReply(addReplyVo);
    }

    /**
     * 查看用户回复评论
     * @param commentId
     * @return
     */
    @Operation(summary = "查看用户回复评论")
    @GetMapping("/user/reply/comment/select/{commentId}")
    public Result userReplyCommentSelect(@PathVariable("commentId") Long commentId){
        return commentReplyService.userReplyCommentSelect(commentId);
    }

    /**
     * 查看用户回复回复
     * @param replyId
     * @return
     */
    @Operation(summary = "查看用户回复回复")
    @GetMapping("/user/reply/select/{replyId}")
    public Result userReplySelect(@PathVariable("replyId") Long replyId){
        return commentReplyService.userReplySelect(replyId);
    }

/**
 * TODO 管理员-评论管理--评论回复
 */
    /**
     * 管理员分页查询评论回复信息
     *
     * @param page
     * @param size
     * @return
     */
    @Operation(summary = "管理员分页查询评论回复信息接口")
    @GetMapping("/admin/page")
    public Result adminPage(@RequestParam(value = "page", defaultValue = "1") Integer page,
                            @RequestParam(value = "size", defaultValue = "5") Integer size) {
        Page<CommentReply> commentReplyPage = commentReplyService.adminPage(page, size);
        return Result.success(commentReplyPage);
    }

    /**
     * 管理员删除单个评论回复信息
     *
     * @param replyId
     * @return
     */
    @Operation(summary = "管理员删除单个评论回复信息接口")
    @DeleteMapping("/admin/delete/{replyId}")
    public Result adminDeleteOne(@PathVariable("replyId") Long replyId) {
        if (commentReplyService.getById(replyId) == null)
            throw new ServiceException("回复信息不存在！");
        commentReplyService.adminDeleteOne(replyId);
        return Result.success();
    }

    /**
     * 管理员批量删除多个评论回复信息
     *
     * @return
     */
    @Operation(summary = "管理员批量删除多个评论回复信息接口")
    @DeleteMapping("/admin/delete/batch")
    public Result adminDeleteBatch(@RequestBody List<Long> replyIds) {
        replyIds.forEach(this::adminDeleteOne);
        return Result.success();
    }
}
